package com.easylinkin.linkappapi.calculaterule.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.annotation.CommonOperateLogAnnotate;
import com.easylinkin.linkappapi.calculaterule.entity.CalculateConfig;
import com.easylinkin.linkappapi.calculaterule.service.CalculateConfigService;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.operatelog.constant.LogConstant.LogModule;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import javax.validation.Valid;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * <p>
 * 计算配置 前端控制器
 * </p>
 *
 * @author TongJie
 * @since 2020-06-17
 */
@RestController
@Api(value = "计算配置", tags = {"计算配置"})
@RequestMapping("/calculaterule/calculateConfig")
public class CalculateConfigController {


    @Resource
    private CalculateConfigService service;

    @ApiOperation("新增计算配置")
    @PostMapping("add")
    @CommonOperateLogAnnotate(module = LogModule.CALCULATE_CONFIG, desc = "新增计算配置")
    public RestMessage add(@RequestBody @Valid CalculateConfig calculateConfig) {
        service.add(calculateConfig);
        return RestBuilders.successBuilder().build();
    }

    @ApiOperation("根据查询条件获取计算配置数据")
    @PostMapping("get")
    public RestMessage getCalculateConfigs(@RequestBody CalculateConfig calculateConfig) {
        Assert.notNull(calculateConfig, "calculateConfig 不能为空");
        return RestBuilders.successBuilder().data(service.getCalculateConfigs(calculateConfig)).build();
    }

    @ApiOperation("获取计算配置分页数据")
    @PostMapping("getPage")
    public RestMessage getCalculateConfigsPage(@RequestBody RequestModel<CalculateConfig> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<CalculateConfig> record = service.getCalculateConfigsPage(requestModel.getPage(), requestModel.getCustomQueryParams());
        return RestBuilders.successBuilder().data(record).build();
    }

    @ApiOperation("根据ID获取计算配置详情")
    @PostMapping("getById")
    public RestMessage getById(@RequestParam("id") String id) {
        Assert.hasLength(id, "id 不能为空");
        return RestBuilders.successBuilder().data(service.getCalculateConfig(id)).build();
    }

    @ApiOperation("修改计算配置")
    @PostMapping("update")
    @CommonOperateLogAnnotate(module = LogModule.CALCULATE_CONFIG, desc = "修改计算配置")
    public RestMessage update(@RequestBody CalculateConfig calculateConfig) {
        service.updateCalculateConfig(calculateConfig);
        return RestBuilders.successBuilder().build();
    }

    @PostMapping("updateStatus")
    @CommonOperateLogAnnotate(module = LogModule.CALCULATE_CONFIG, desc = "修改计算配置状态")
    @ApiOperation("修改计算配置状态")
    public RestMessage updateStatus(@RequestBody CalculateConfig calculateConfig) {
        service.updateStatus(calculateConfig);
        return RestBuilders.successBuilder().build();
    }

    @ApiOperation("批量删除计算配置")
    @PostMapping("deleteBatch")
    @CommonOperateLogAnnotate(module = LogModule.CALCULATE_CONFIG, desc = "批量删除计算配置")
    public RestMessage deleteBatch(@RequestBody List<CalculateConfig> calculateConfigList) {
        Assert.notEmpty(calculateConfigList, "参数为空");
        service.deleteBatch(calculateConfigList);
        return RestBuilders.successBuilder().build();
    }

}


